//
//  ViewController.m
//  Lesson
//
//  Created by centling on 15/4/10.
//  Copyright (c) 2015年 Seas.CHENG. All rights reserved.
//

#import "ViewController.h"
#import "xibViewController.h"
#import "codeViewController.h"
#import "Global.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUserName:) name:UPDATENAMENOTIFICATION object:nil];
    
    
    
    int mu=5;
    int (^block)(int)=^(int num){
        return num*mu;
    };
    
    NSLog(@"block:%d",  block(5));
    
    // Do any additional setup after loading the view, typically from a nib.
}


-(void)updateUserName:(NSNotification *)notification{
    NSLog(@"notification:%@",notification);
    self.userNameTextField.text=[notification.userInfo objectForKey:@"name"];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)loginButtonClick:(id)sender {
    
    NSString *name=self.userNameTextField.text;
    NSString *pwd=self.userPwdTextField.text;
    
    
    BOOL success=[self checkUserName:name userPwd:pwd];
    if (success) {
        NSLog(@"success");
    };
    if (!success) {
        NSLog(@"failed");
    };
    
    
    //页面跳转三种方式
    //1.使用xib新建的ViewController
//    xibViewController *xibVC=[[xibViewController alloc] initWithNibName:@"xibViewController" bundle:nil];
//    [self presentViewController:xibVC animated:YES completion:nil];
    
    //2.使用纯代码新建的VC
//    codeViewController *codeVC=[[codeViewController alloc] init];
//    [self presentViewController:codeVC animated:YES completion:nil];
    
    
//    3.在storyboard中新建的VC
//    UIStoryboard *storyboard=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    
    UIViewController *jumpPageVC=[self.storyboard instantiateViewControllerWithIdentifier:@"jumppage"];
    [self presentViewController:jumpPageVC animated:YES completion:nil];
    
    
    
    
//    NSLog(@"测试～～～");
//    NSString *strTest=@"test";
//    int num=1;
//    NSLog(@"%d     %@",num,strTest);
}

- (IBAction)hiddenButtonClick:(id)sender {
    [self.userPwdTextField resignFirstResponder];
    [self.userNameTextField resignFirstResponder];
}


-(BOOL)checkUserName:(NSString *)username userPwd:(NSString *)pwd{
    NSLog(@"Name:%@  Pwd:%@",username,pwd);
    if ([username isEqualToString:@"seas"]&&[pwd isEqualToString:@"123"]) {
        return YES;
    }else{
        return NO;
    }
}
@end
